#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;

#endregion

namespace Weazel.Gezel.Model
{
  /// <summary>
  /// A lookup table is a read-only array of constants which
  /// can be read during simulation. A lookup table can only be
  /// declared inside a datapath to which it is local.
  /// </summary>
  public partial class LookupTable : AbstractEntity<Datapath>, ITypedEntity
  {
    /// <summary>
    /// The bitwidth of the constants in the table.
    /// </summary>
    private int width;
    public int Width
    {
      get
      {
        return width;
      }
			protected set
			{
				width = value;
			}
    }

    /// <summary>
    /// True iff the constants are signed.
    /// </summary>
    private bool signed;
    public bool Signed
    {
      get
      {
        return signed;
      }
			protected set
			{
				signed = value;
			}
    }

    /// <summary>
    /// The constants stored in the lookup table.
    /// </summary>
    private Integer[] values;
    public Integer[] Values
    {
      get
      {
        return values;
      }
			protected set
			{
				values = value;
			}
    }

    /// <summary>
    /// Returns the constant at the given index.
    /// </summary>
    /// <param name="index">array index</param>
    /// <returns>the constant stored at the specified index</returns>
    public Integer this[int index]
    {
      get
      {
        return values[index];
      }
    }

		protected LookupTable(Datapath parent, string name)
			: base(parent, name)
		{
		}

		public LookupTable(
			Datapath parent, 
			string name, 
			Integer[] values, 
			int bitWidth, 
			bool signed, 
			Position startPosition,
			Position endPosition
		)
			: this(parent, name, values, bitWidth, signed)
    {
			this.startPosition = startPosition;
			this.endPosition = endPosition;
    }

    /// <summary>
    /// Constructs and fully initializes a new LookupTable.
    /// </summary>
    /// <param name="parent">parent datapath</param>
    /// <param name="name">name of the table</param>
    /// <param name="values">lookup table contents</param>
    /// <param name="bitWidth">bitwidth of the contents</param>
    /// <param name="signed">true iff the contents are signed</param>
    public LookupTable(Datapath parent, string name, Integer[] values, int bitWidth, bool signed) : base(parent, name)
    {
      this.values = values;
      this.width = bitWidth;
      this.signed = signed;
    }
  }
}